package com.wjf.shortlink.shortlink.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.wjf.shortlink.shortlink.common.convention.result.Results;
import com.wjf.shortlink.shortlink.common.convention.result.Result;
import com.wjf.shortlink.shortlink.dto.req.ShortLinkGroupStatsAccessRecordReqDTO;
import com.wjf.shortlink.shortlink.dto.req.ShortLinkGroupStatsReqDTO;
import com.wjf.shortlink.shortlink.dto.req.ShortLinkStatsAccessRecordReqDTO;
import com.wjf.shortlink.shortlink.dto.req.ShortLinkStatsReqDTO;
import com.wjf.shortlink.shortlink.dto.resp.ShortLinkStatsAccessRecordRespDTO;
import com.wjf.shortlink.shortlink.dto.resp.ShortLinkStatsRespDTO;
import com.wjf.shortlink.shortlink.service.ShortLinkStatsService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
public class ShortLinkStatsController {
    private final ShortLinkStatsService shortLinkStatsService;

    //访问单个链接指定时间内监控数据
    @GetMapping("/api/short-link/v1/stats")
    public Result<ShortLinkStatsRespDTO> shortLinkStats(ShortLinkStatsReqDTO reqDTO) {
        return Results.success(shortLinkStatsService.oneShortLinkStats(reqDTO));
    }

    //访问分组短链接指定时间内监控数据
    @GetMapping("/api/short-link/v1/stats/group")
    public Result<ShortLinkStatsRespDTO> groupShortLinkStats(ShortLinkGroupStatsReqDTO reqDTO) {
        return Results.success(shortLinkStatsService.groupShortLinkStats(reqDTO));
    }

    //获取单个链接指定时间内分页监控数据
    @GetMapping("/api/short-link/v1/stats/access-record")
    public Result<IPage<ShortLinkStatsAccessRecordRespDTO>> shortLinkStatsAccessRecord(ShortLinkStatsAccessRecordReqDTO reqDTO) {
        return Results.success(shortLinkStatsService.shortLinkStatsAccessRecord(reqDTO));
    }

    //获取分组短链接指定时间内分页监控数据
    @GetMapping("/api/short-link/v1/stats/access-record/group")
    public Result<IPage<ShortLinkStatsAccessRecordRespDTO>> groupShortLinkStatsAccessRecord(ShortLinkGroupStatsAccessRecordReqDTO reqDTO) {
        return Results.success(shortLinkStatsService.groupShortLinkStatsAccessRecord(reqDTO));
    }
}
